<?php
/*
 module:		简历投递记录
 create_time:	2024-03-13 09:52:47
 author:		
 contact:		
*/

namespace app\api\controller;

use app\api\model\Personaljobsapply as PersonaljobsapplyModel;
use app\api\service\PersonaljobsapplyService;

class Personaljobsapply extends Common
{

    /*start*/
    /**
     * @api {get} /Personaljobsapply/index 01、首页数据列表
     */
    function index()
    {
        $limit = $this->request->get('limit', 20, 'intval');
        $page = $this->request->get('page', 1, 'intval');
        $apply_status = $this->request->get('apply_status', 1, 'intval');
        $where = [];
        if (!empty($apply_status) && $apply_status != 0) {
            $where['apply_status'] = $apply_status;
        }
        $where['personal_uid'] = $this->request->uid;
        $field = '*';
        $orderby = 'did desc';

        $res = PersonaljobsapplyService::indexList(formatWhere($where), $field, $orderby, $limit, $page);
        return $this->ajaxReturn($this->successCode, '返回成功', htmlOutList($res));
    }

    /**
     * @api {post} /Personaljobsapply/add 02、投递简历
     */
    function add()
    {
        $jobs_id = $this->request->post('jobs_id', 0, 'intval');
        $uid = $this->request->uid;
        $jobs = \app\api\model\Jobs::where("id", $jobs_id)->field("id,jobs_name,company_id,companyname")->findOrEmpty()->toArray();
        if (empty($jobs)) return $this->ajaxReturn($this->errorCode, '职位已下架');
        $resume = \app\api\model\Resume::where("uid", $uid)->order("id DESC")->field("id,title")->findOrEmpty()->toArray();
        if (empty($resume)) return $this->ajaxReturn($this->errorCode, '请完善简历');
        $info = PersonaljobsapplyModel::where(["jobs_id" => $jobs["id"], "personal_uid" => $uid])->find();
        if (!empty($info)) return $this->ajaxReturn($this->errorCode, '请勿重复投递');
        $company_uid = \app\api\model\Companyprofile::where("id", $jobs["company_id"])->value("uid");
        $res = PersonaljobsapplyService::add([
            "resume_id" => $resume["id"],
            "resume_name" => $resume["title"],
            "personal_uid" => $uid,
            "jobs_id" => $jobs["id"],
            "jobs_name" => $jobs["jobs_name"],
            "company_id" => $jobs["company_id"],
            "company_name" => $jobs["companyname"],
            "company_uid" => empty($company_uid) ? 0 : $company_uid,
            "apply_addtime" => time(),
            "personal_look_time" => "",
            "personal_look" => 1,
            "notes" => "",
            "is_reply" => 0,
            "is_apply" => 1,
            "reply_time" => "",
            "apply_status" => 1
        ]);
        return $this->ajaxReturn($this->successCode, '投递成功', $res);
    }

    /*end*/

}

